package com.tincher.twebutil

import android.animation.ObjectAnimator
import android.graphics.Color
import android.os.Bundle
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.collection.ArrayMap
import com.just.agentweb.DsAgentWeb
import com.just.agentweb.DefaultWebClient
import kotlinx.android.synthetic.main.main_activity.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.main_activity)
        DsAgentWeb.with(this)
            .setAgentWebParent(ll_web, ViewGroup.LayoutParams(-1, -1))
            .useDefaultIndicator(Color.GREEN,5)
            .addLifeCycleOwner()//绑定生命周期，使用后可不在activity生命周期改变时处理webview
//            .addJavascriptInterface("echo",TestApi())//原始js交互方法最好不要使用
            .addDSJavascriptInterface(TestApi(),null)//正确的js交互方法，dsbridge
            .addDSJavascriptInterface(JsApii(),"echo")
            //也可以以ArrayMap对象形式传入
//            .addDSJavascriptInterface(
//                ArrayMap<Any,String>().apply {
//                    put(TestApi(),null)
//                    put(JsApii(),"echo")
//                }
//            )
            .setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.ASK)
            .setMainFrameErrorView(R.layout.agentweb_error_page, -1)
            .createAgentWeb()
            .ready()
            .go("file:///android_asset/js-call-native.html")
    }

}
